# image 相关的操作的模块
# 1. 向一个img写text
# 1. 向一个img写入 qrcode

import qrcode
from PIL import Image,ImageFont,ImageDraw

# 证书类
class ImageCert(object):

    """Docstring for ImageCert. """

    # 打开的图片的位置
    def __init__(self,imagePath,fontPath):
        """TODO: to be defined. """
        self.im = Image.open(imagePath)
        self.img_editable =  ImageDraw.Draw(self.im)
        self.fontPath = fontPath
        self.fontsize = 200

    def set_font_size(self,size):
        self.fontsize = size

    def draw_text(self,xy,text,fill = (0,0,0)):
        font = ImageFont.truetype(self.fontPath,self.fontsize)
        self.img_editable.text(xy,text,fill = fill ,font = font)

    def save(self,path):
        self.im.save(path)

    def qrcode(self,xy,text):
        __qrcode = qrcode.make(text)
        self.im.paste(__qrcode,xy)

    # 把一个图片复制到图片上来
    def pasteImg(self,xy,_img_path):
        tmp_img = Image.open(_img_path)
        self.im.paste(tmp_img,xy,tmp_img)

    # 把一个图片复制到图片上来
    def pasteImg(self,xy,_img_path,scale_x,scale_y):
        tmp_img = Image.open(_img_path)
        # resize_img = tmp_img.resize((tmp_img.width *scale_x , tmp_img.height * scale_y ))
        resize_img = tmp_img.resize(( int(tmp_img.width*scale_x),int(tmp_img.height*scale_y)))
        self.im.paste(resize_img,xy,resize_img)

    def show(self):
        self.im.show()


